<template>
	<yd-layout>
		<yd-navbar
			slot="navbar"
			title
			style="height:1rem;background:red"
			class="in_serch"
		>
			<router-link
				to="#"
				slot="center"
			>
				<yd-search
					v-model="keyword"
					:on-submit="search_business"
				></yd-search>
			</router-link>
		</yd-navbar>
		<div>
			<!-- <input type="button" value="分享" @click="share_business">
      <poster :share="share" @sharelink="share_img"></poster>-->
			<yd-tab>
				<yd-tab-panel label="最近">
					<yd-infinitescroll
						:distance="20"
						:callback="get_business_lately_list"
						ref="business_lately"
					>
						<div
							class="conten"
							slot="list"
						>
							<team-business
								:store_data="item"
								v-for="(item, index) in business_lately.content_list"
								:key="index"
							></team-business>
						</div>
						<span slot="doneTip">没有更多了</span>
					</yd-infinitescroll>
				</yd-tab-panel>
				<yd-tab-panel label="评分">
					<yd-infinitescroll
						:distance="20"
						:callback="get_business_score_list"
						ref="business_score"
					>
						<div
							class="conten"
							slot="list"
						>
							<team-business
								:store_data="item"
								v-for="(item, index) in business_score.content_list"
								:key="index"
							></team-business>
						</div>
						<span slot="doneTip">没有更多了</span>
					</yd-infinitescroll>
				</yd-tab-panel>
				<yd-tab-panel label="销量">
					<yd-infinitescroll
						:distance="20"
						:callback="get_business_sales_list"
						ref="business_sales"
					>
						<div
							class="conten"
							slot="list"
						>
							<team-business
								:store_data="item"
								v-for="(item, index) in business_sales.content_list"
								:key="index"
							></team-business>
						</div>
						<span slot="doneTip">没有更多了</span>
					</yd-infinitescroll>
				</yd-tab-panel>
			</yd-tab>
			<div
				id="allmap"
				style="display:none;"
			></div>
		</div>
	</yd-layout>
</template>

<script>
import poster from "@/components/poster/index";
import teamBusiness from "@/components/organize_team/business";
import { location } from "@/toolset/map";

export default {
	name: "BusinessList",
	data () {
		return {
			business_type: this.$route.params.business_type,
			keyword: "",
			share: false,
			page_size: 10,
			business_lately: {
				page_index: 1,
				content_list: [
				]
			},
			business_score: {
				page_index: 1,
				content_list: [
				]
			},
			business_sales: {
				page_index: 1,
				content_list: [

				]
			}
		};
	},
	components: {
		teamBusiness,
		poster
	},
	mounted () {
		//设置当前用户不是通过邀请进入的

		this.$store.commit("IS_INVITATION", false);
		this.$store.commit("ORDER_ID", 0);
		this.$store.commit("SHARE_ID", 0);
		this.$store.commit("ORGANIZE_TYPE", "");
		this.$store.commit("CLEAR_ACCOUNT_MENUS");
		// 获取当前用户的位置信息
		// this.get_location();

		// 查询商家列表
    this.get_business_lately_list()
    this.get_business_score_list()
    this.get_business_sales_list()
	},
	methods: {
		/*
		 * 使用ip获取当前定位信息
		 * 作者：gzt
		 * 时间：2019-11-26 12:20:24
		 */
		get_ip_location () {
			AMap.plugin("AMap.CitySearch", function () {
				var citySearch = new AMap.CitySearch();
				citySearch.getLocalCity(function (status, result) {
					if (status === "complete" && result.info === "OK") {
						// 查询成功，result即为当前所在城市信息
						console.log(result);
					}
				});
			});
		},

		/*
		 * 获取当前位置
		 * 作者：gzt
		 * 时间：2019-11-26 11:27:28
		 */
		get_location () {
			// var map = new BMap.Map("allmap");
			// var point = new BMap.Point(116.331398, 39.897445);
			// map.centerAndZoom(point, 12);
			// var geolocation = new BMap.Geolocation();

			// geolocation.getCurrentPosition(function (r) {
			// 	if (this.getStatus() == BMAP_STATUS_SUCCESS) {
			// 		var mk = new BMap.Marker(r.point);
			// 		map.addOverlay(mk);
			// 		map.panTo(r.point);
			// 		console.log(r)

			// 	} else {
			// 		console.log(r)

			// 	}
			// });

			// console.log('高德地图的获取位置')
			// let _this = this;
			// let geolocation_a = location.initMap("map-container"); //定位
			// AMap.event.addListener(geolocation_a, "complete", result => {
			// 	console.log(result)
			// });
			// AMap.event.addListener(geolocation_a, "error", onError => {

			// 	console.log(onError)
			// 	_this.get_ip_location();
			// });
		},

		/*
		 * 搜索商家列表
		 * 作者：gzt
		 * 时间：2019-11-26 09:34:17
		 */
		search_business () {
			console.log(1);
		},
		// 分享按钮
		share_business () {
			this.share = true;
		},
		share_img (img_url) { },
		/*
		 * 获取最近的商家
		 * 作者：gzt
		 * 时间：2019-11-26 09:20:37
		 */
		get_business_lately_list () {
			let _this = this
			this.$post(this.$api.organizeteam.get_business_list, {
				pageSize: this.page_size,
				pageNum: this.business_lately.page_index,
				request: {
					bussinesType: this.business_type,
					sort: 'DISTANCE_ASC'
				}
			})
				.then(res => {
					if (res.success) {
						_this.business_lately.content_list = [..._this.business_lately.content_list, ...res.data.result]
						if (res.data.result.length < this.page_size) {
							/* 所有数据加载完毕 */
							_this.$refs.business_lately.$emit("ydui.infinitescroll.loadedDone");
							return;
						}
						/* 单次请求数据完毕 */
						_this.$refs.business_lately.$emit("ydui.infinitescroll.finishLoad");

						_this.business_lately.page_index++;
					}
				}).catch(error => {
					console.log(error);
				})
		},
		/*
		 * 获取评分最高的商家
		 * 作者：gzt
		 * 时间：2019-11-26 09:20:55
		 */
		get_business_score_list () {
			let _this = this
			this.$post(this.$api.organizeteam.get_business_list, {
				pageSize: this.page_size,
				pageNum: this.business_score.page_index,
				request: {
					bussinesType: this.business_type,
					sort: 'SCORE_DESC'
				}
			})
				.then(res => {
					if (res.success) {
						_this.business_score.content_list = [..._this.business_score.content_list, ...res.data.result]
						if (res.data.result.length < this.page_size) {
							/* 所有数据加载完毕 */
							this.$refs.business_score.$emit("ydui.infinitescroll.loadedDone");
							return;
						}
						/* 单次请求数据完毕 */
						this.$refs.business_score.$emit("ydui.infinitescroll.finishLoad");

						this.business_score.page_index++;
					}
				}).catch(error => {
					console.log(error);
				})
		},
		/*
		 * 获取销量最高的商家
		 * 作者：gzt
		 * 时间：2019-11-26 09:21:19
		 */
		get_business_sales_list () {
			let _this = this
			this.$post(this.$api.organizeteam.get_business_list, {
				pageSize: this.page_size,
				pageNum: this.business_sales.page_index,
				request: {
					bussinesType: this.business_type,
					sort: 'SALES_DESC'
				}
			})
				.then(res => {
					if (res.success) {
						_this.business_sales.content_list = [..._this.business_sales.content_list, ...res.data.result]
						if (res.data.result.length < this.page_size) {
							this.$refs.business_sales.$emit("ydui.infinitescroll.loadedDone");
							return;
						}
						/* 单次请求数据完毕 */
						this.$refs.business_sales.$emit("ydui.infinitescroll.finishLoad");

						this.business_sales.page_index++;
					}
				}).catch(error => {
					console.log(error);
				})
		}
	}
};
</script>
<style>
.in_serch {
	align-items: center;
	/* background: url(../../static/home/1.png); */
	background-color: #f23030;
}

.yd-search-input {
	width: 7.2rem;
	padding: 0px;
	border-radius: 20px;
}

.yd-search-input > .search-input {
	margin-right: 0px;
}

.yd-search-input > .search-input {
	border-radius: 20px;
}

.yd-search-input:after,
.yd-search-input:before {
	height: 0px;
}

.yd-search-input:after,
.yd-search-input:before {
	height: 0px;
}

.yd-navbar:after {
	height: 0px;
}

/* 类别选择按钮模块样式sta */
.sh_type {
	display: flex;
	width: 7rem;
}

.sh_type div {
	margin: 0rem 0.2rem;
	font-size: 0.3rem;
	width: 2.1rem;
	padding: 0.05rem 0.1rem;
}

.type {
	display: flex;
	align-items: center;
	justify-content: center;
	border: 1px solid #999;
	border-radius: 50px;
	color: #999;
}

.ok {
	background-image: linear-gradient(
		to right,
		rgb(119, 227, 235),
		rgb(19, 130, 233)
	);
	border-radius: 50px;
	border: none;
	color: #fff;
}

.type img {
	height: 0.35rem;
	padding-right: 0.08rem;
}

/* 类别选择按钮模块样式end */
/* 商家列表 sta*/
.conten {
	background: #f5f5f5;
}

/* 商家列表 end*/
</style>
